<?php
/**
 * base class for text files
 *
 * This file is part of Webappkit, a packages system for PHP web apps
 * @link http://webappkit.net
 * @package webappkit
 * @subpackage fs
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
class WakTextFile extends WakFile {

    /**
     * Add carriage return, new line, and some content
     * @param string $content optional
     * @return bool
     */
    public function newLine($content='') {
        if (!$this->toEnd()
        or !$this->write(chr(13).chr(10).$content))
            return false;
        $this->close();
        return true;
    }

    /**
     * Set all content at once
     * @param string $content
     * @return bool
     */
    public function setContent($content) {
        if (!$this->erase()
        or !$this->write($content,0))
            return false;
        $this->close();
        return true;
    }

    /**
     * get all content at once
     * @return string
     */
    public function getContent() {
        $content='';
        if (!$content=$this->read())
            return false;
        $this->close();
        return $content;
    }
}
